﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Validity.Test.Constraints.StringConstraints
{
  [TestClass]
  public class IsNotEmptyConstraint
    : ConstraintTestBase<ObjectStub>
  {
    public class Validator
      : ValidatorBase<ObjectStub>
    {
      public Validator()
      {
        DefineRulesFor(ctx => ctx.MyStringProperty1).IsNotEmpty();
      }
    }

    public IsNotEmptyConstraint() : base(new Validator(), 1) { }

    [TestMethod]
    public void TestConstraintVerified()
    {
      ValidateConstraintVerfied(CreateContext(" "));
      ValidateConstraintVerfied(CreateContext("OTHER"));
      ValidateConstraintVerfied(CreateContext(Environment.NewLine));
    }

    [TestMethod]
    public void TestConstraintViolated()
    {
      const String ruleViolation = "A value is required";

      ValidateConstraintViolated(CreateContext(null), ruleViolation);
      ValidateConstraintViolated(CreateContext(String.Empty), ruleViolation);
    }

    public ObjectStub CreateContext(String value)
    {
      var result = new ObjectStub();

      result.MyStringProperty1 = value;

      return result;
    }
  }
}
